import os

filename = "stundents"


def save(student):
    try:
        students_txt =os.open(filename,"a")
    except Exception as e:
        students_txt = os.open(filename,"w")
    for info in student:
        students_txt = os.write(info+"\n")
    students_txt.close()


def insert():
    students_list = []
    mark = True
    while mark:
        id = input("请输入学生ID:例如（1001）")
        if not id:
            break
        name = input("请输入学生姓名：")
        if not name:
            break
        try:
            english = int(input("请输入学生英语成绩"))
            python = int(input("请输入学生python成绩"))
            c = int(input("请输入学生C语言成绩"))
        except:
            print('输入有误，请重新输入')
            continue
        student = {"id": id, "name": name, "英语成绩": english, "python成绩": python, "C语言成绩": c}
        students_list.append(student)
        input_mark = input("是否继续输入(y/n):")
        if input_mark == "y":
            mark = True
        else:
            mark = False
        save(students_list)
        print("学生信息录入完毕")


if __name__ == "__main__":
    insert()